Learning Flex Basics (Part 3) : Working with Containers
Table of Contents
- Introduction
- Building the Containers
- Create the Application Object
- Create a Data Array
- Add a TabNavigator Container for Global Navigation
- Add an HBox and Panel Containers for Main Views
- Add a ViewStack, LinkBar, and Panel Containers for Secondary Views
- Add a Form Container
- Add a Tile Layout Container and Populate It Using a Repeater
- Create a Pseudo Bar Chart Using a Repeater and VBoxes
- Complete Code Listing for containers.mxml
- Where to Go from Here
Add a ViewStack, LinkBar, and Panel Containers for Secondary Views
The base class for the TabNavigator container is the ViewStack navigator
container, which contains an array of containers and lets you manage
navigation between them through either the selectedIndex or selectedItem property
(the first references a container by its position in the array, the second
by its id value). The TabNavigator container extends the ViewStack class,
and so has its ViewStack "built-in"; other navigation
containers use a separately defined ViewStack container as a dataProvider,
but still provide the transparent handling of navigation.
The LinkBar navigator container has a direction property that you can set to horizontal or vertical, making it useful for either global or section navigation; here you use it for the latter.
-
Inside the HBox container, add a ViewStack container with the id vStack :
<mx:ViewStack id="vStack"> </mx:ViewStack>
-
Before the ViewStack container, but still inside the HBox container, add a LinkBar container with a dataProvider bound to the ViewStack container and direction attribute set to vertical:
<mx:LinkBar dataProvider="{vStack}" direction="vertical"/> -
Inside the ViewStack container, add two Panels, the first has both
titleandlabelproperties set to Form; the second hastitleandlabelset to Tile and anidof tilePanel:<mx:Panel title="Form" label="Form"> </mx:Panel> <mx:Panel id="tilePanel" title="Tile" label="Tile"> </mx:Panel>
- Save the file and browse it. Click the two tabs and the two links of the LinkBar container to see the automatic handling of navigation. Also try the browser's back and forward buttons; the navigation containers tie navigation events to the browser's history so that the back and forward buttons work just as they would if these were normal web pages.